package edu.ccut.saturn.basecomponent.database.impl.sqlserver.handler.unused;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

import edu.ccut.saturn.basecomponent.database.ISaturnSQL;
import edu.ccut.saturn.basecomponent.database.impl.AbstractSQLHandler;
import edu.ccut.saturn.basecomponent.database.impl.mysql.MysqlSetPrimaryKeyInSaturnData;
import edu.ccut.saturn.component.SaturnComponentException;
import edu.ccut.saturn.component.SaturnData;

public class MysqlInsertSQLHandler extends AbstractSQLHandler {

	public List<SaturnData> executeQuery(ISaturnSQL saturnSQL,
			Connection connection) throws SaturnComponentException {
		return null;
	}

	public int executeUpdate(ISaturnSQL saturnSQL, Connection connection)
			throws SaturnComponentException {
		if(connection!=null){
			Statement statement = null;
			int result = 0;
			try {
				statement = connection.createStatement();
				result = statement.executeUpdate(saturnSQL.getSql());
				MysqlSetPrimaryKeyInSaturnData.setPrimaryKeyValue(connection, saturnSQL);
				return result;
			} catch (SQLException e) {
				throw new SaturnComponentException(e);
			}finally{
				if(statement != null){
					try {
						statement.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
			}
		} else{
			throw new SaturnComponentException("Connection is null");
		}
	}
}
